//表单加载时，初始化
function initForm(fromId){
			var options = {
			beforeSubmit : showRequest, //提交前处理 
			success : showResponse, //处理完成 addYSLine
			//resetForm : true,
			dataType : 'json'
		}
		$('#'+fromId).submit(function() {
			$('#'+fromId).ajaxSubmit(options);
				return false; 
		});
}
//选择协议弹出框
function selSup(){
	var url="../uc_contract/contract-sup-select.html";
	openLayer(url,'1020','600');
}
//生成协议记录
function creatBG(resultJson){
	var html="<table><table class='table table-condensed'><thead><tr><th>变更条款</th><th>原内容</th><th>变更内容</th></tr></thead><tbody>";
	var html_tr="";
	for(var i=0;i<resultJson.length;i++){
		html_tr=html_tr+"<tr><td>"+resultJson[i].type+"</td><td>"+resultJson[i].pastData+"</td><td>"+resultJson[i].curData+"</td></tr>";
	}
	html=html+html_tr+"</tbody></table>";
	window.parent.$("#supList").html(html);
}

//生成应收列表
function createYS(temp){
	var sdate_str=$("#sdate").val();
	var edate_str=$("#edate").val();
	var payType=$("#fk_payment").val();
	var curDate=StringToDate("2016-01-01");
	var ysList="[";
	var ys="";
	var monthCount=$("#"+payType).attr("data-option");
	var sdate,edate;
	if(sdate_str!="" && edate_str!=""){
		sdate=StringToDate(sdate_str);
		edate=StringToDate(edate_str);
		if(temp==true){
			if(sdate<curDate){
				sdate=curDate;
			}			
		}
		var  diffMonth=sdate.DateDiff('m',edate);
		diffMonth=Math.ceil(diffMonth/monthCount);
		if(monthCount!=0){
			for(var i=0;i<=diffMonth;i++){
				if(sdate.DateAdd('m',(i)*monthCount)<=edate){
					ys=ys+",{\"dateYear\":\""+sdate.DateAdd('m',(i)*monthCount).Format("yyyy")
							+"\",\"dateMonth\":\""+sdate.DateAdd('m',(i)*monthCount).Format("MM")+"\"}";
				}else{
					ys=ys+",{\"dateYear\":\""+edate.Format("yyyy")+"\",\"dateMonth\":\""+edate.Format("MM")+"\"}";
				}
			}
		}else{
			ys=ys+",{\"dateYear\":\""+sdate.Format("yyyy")+"\",\"dateMonth\":\""+sdate.Format("MM")+"\"}";
		}
	ys=ys.substring(1,ys.length);
	ysList=ysList+ys+"]";
	ysList=eval('(' + ysList + ')');
	var html="<table class='table table-condensed'><thead><tr><th>次数</th><th>预计缴款时间</th><th>预计缴款金额</th></tr></thead><tbody>";
	var trHtml="";
	var k = 0;
	for(var i=0;i<ysList.length;i++){
		if(i>0){
			trHtml=trHtml+"<tr id='tr"+i+"'><td>第"+(i+1)+"次<input type='hidden' readOnly id='receivableId"+i+"' name='receivableId"+i+"' value='' /></td><td>年:<input type='text' readOnly name='dateYear"+i+"'  id='dateYear"+i+"' value='"+ysList[i].dateYear+"' size='5'/>&nbsp;<input type='button' value='+' onclick=\"calcAdd('dateYear"+i+"')\" />&nbsp;<input type='button' value='-' onclick=\"calcJian('dateYear"+i+"')\" />&nbsp;月:<input type='text' readOnly name='dateMonth"+i+"'  id='dateMonth"+i+"' value='"+ysList[i].dateMonth+"' size='5'/>&nbsp;<input type='button' value='+' onclick=\"calcAdd('dateMonth"+i+"')\" />&nbsp;<input type='button' value='-' onclick=\"calcJian('dateMonth"+i+"')\" /></td> <td><input type='text' id='jine"+i+"' name='jine"+i+"' value='' />元<input type='button' size='10' value='同上' onClick=autoVal("+i+") /></td><td><a style='curosor:pointer' onClick=delYS('"+i+"')>删除</a></td></tr>"
		}else{
			trHtml=trHtml+"<tr id='tr"+i+"'><td>第"+(i+1)+"次<input type='hidden' readOnly id='receivableId"+i+"' name='receivableId"+i+"' value='' /></td><td>年:<input type='text' readOnly name='dateYear"+i+"'  id='dateYear"+i+"' value='"+ysList[i].dateYear+"' size='5'/>&nbsp;<input type='button' value='+' onclick=\"calcAdd('dateYear"+i+"')\" />&nbsp;<input type='button' value='-' onclick=\"calcJian('dateYear"+i+"')\" />&nbsp;月:<input type='text' readOnly name='dateMonth"+i+"'  id='dateMonth"+i+"' value='"+ysList[i].dateMonth+"' size='5'/>&nbsp;<input type='button' value='+' onclick=\"calcAdd('dateMonth"+i+"')\" />&nbsp;<input type='button' value='-' onclick=\"calcJian('dateMonth"+i+"')\" /></td> <td><input type='text' id='jine"+i+"' name='jine"+i+"' value='' />元</td><td><a style='curosor:pointer' onClick=delYS('"+i+"')>删除</a></td></tr>"
		}
		k++;
	}
	html=html+trHtml+"</tbody></table>";
	if(k>=12){
		$("#ysList").css({"overflow":"auto","width":"1024px","height":"480px"});
	}else{
		$("#ysList").css({"width":"1024px"});
	}
	$("#ysList").html(html);
  }	

}
function delYS(i){
	if(confirm("确定删除此条应收吗?")){
		$("#tr"+i).remove();
	}
}
function calcAdd(id){
	var n=$("#"+id).val();
	if(n.indexOf("0")==0){
		n=n.substring(1);
	}
	var num=parseInt(n)+1;
	if(num>12&&id.indexOf('Month')!=-1){
		num="1";
	}
	if(parseInt(num)<10){
		num="0"+num;
	}
  	$("#"+id).val(num);
}

function calcJian(id){
	
	var n=$("#"+id).val();
	if(n.indexOf("0")==0){
		n=n.substring(1);
	}
  	var num=parseInt(n)-1;
  	if(num<1&&id.indexOf('Month')!=-1){
		num=12;
	}
  	if(parseInt(num)<10){
		num="0"+num;
	}
  	$("#"+id).val(num);
}

function autoVal(index){
	if(index>0){
		var pastV=$("#jine"+(index-1)).val();
		$("#jine"+index).val(pastV);
	}
}
function doAllCheck(){
	//验证免租期
	var length=0;
	var flag=true;
	length=$("#dynMzq").find("tr").length;
	for(var i=0;i<length-1;i++){
		var mzq=$("#mzqAll"+i).val();
		var sdate=$("#mzq_s"+i).val();
		var edate=$("#mzq_e"+i).val();
		if(sdate==""){
			layer.alert("第"+(i+1)+"行免租期开始日期不能为空",{icon:7},function(i){
				layer.close(i);
				$("#mzq_s"+i).focus();
			});
			flag=false;
		}
		if(edate==""){
			layer.alert("第"+(i+1)+"行免租期结束日期不能为空",{icon:7},function(i){
				layer.close(i);
				$("#mzq_e"+i).focus();
			});
			flag=false;
		}
		if(mzq==""){
			layer.alert("第"+(i+1)+"行免租期总天数不能为空",{icon:7},function(i){
				layer.close(i);
				$("#mzqAll"+i).focus();
			});
			flag=false;
		}
		if(!checkNumber(mzq)){
			layer.alert("第"+(i+1)+"行免租期总天数不合法",{icon:7},function(i){
				layer.close(i);
				$("#mzqAll"+i).focus();
			});
			flag=false;
		}
	}
	if(!flag){
		return false;
	}
	//验证租金单价
	length=$("#djList").find("tr").length;
	for(var i=0;i<length-1;i++){
		var zjdj=$.trim($("#zujin"+i).val());
		var yzj=$("#yzj"+i).val();
		var sdate=$("#sdate"+i).val();
		var edate=$("#edate"+i).val();
		if(sdate==""){
			layer.alert("第"+(i+1)+"行租金单价开始日期不能为空",{icon:7},function(i){
				layer.close(i);
				$("#sdate"+i).focus();
			});
			flag=false;
		}
		if(edate==""){
			layer.alert("第"+(i+1)+"行租金单价结束日期不能为空",{icon:7},function(i){
				layer.close(i);
				$("#edate"+i).focus();
			});
			flag=false;
		}
		if(zjdj==""){
			layer.alert("第"+(i+1)+"行租金单价不能为空",{icon:7},function(i){
				layer.close(i);
				$("#zujin"+i).focus();
			});
			flag=false;
		}else if(zjdj>100){
			layer.alert("第"+(i+1)+"行租金单价大于100，请核对数据",{icon:7},function(i){
				layer.close(i);
				$("#zujin"+i).focus();
			});
			flag=false;
		}
		if(!checkNumber(zjdj)){
			layer.alert("第"+(i+1)+"行租金单价不合法",{icon:7},function(i){
				layer.close(i);
				$("#zujin"+i).focus();
			});
			flag=false;
		}
		if(yzj==""){
			layer.alert("第"+(i+1)+"行月租金不能为空",{icon:7},function(i){
				layer.close(i);
				$("#yzj"+i).focus();
			});
			flag=false;
		}
		if(!checkNumber(yzj)){
			layer.alert("第"+(i+1)+"行月租金不合法",{icon:7},function(i){
				layer.close(i);
				$("#yzj"+i).focus();
			});
			flag=false;
		}
	}
	if(!flag){
		return false;
	}
	//验证应收
	length=$("#ysList table").find("tr").length;
	for(var i=0;i<length-1;i++){
		if($("#jine"+i).val()){			
			var jine=$.trim($("#jine"+i).val());
			if(jine==""){
				layer.alert("第"+(i+1)+"次应收金额不能为空",{icon:7},function(i){
					layer.close(i);
					$("#jine"+i).focus();
				});
				flag=false;
			}
			if(!checkNumber(jine)){
				layer.alert("第"+(i+1)+"次应收金额不合法",{icon:7},function(i){
					layer.close(i);
					$("#jine"+i).focus();
				});
				flag=false;
			}
		}
	}
	if(!flag){
		return false;
	}
	return true;
}
//新增数据模版相关js
function doSel(fieldType){
	var selList=getSelList(fieldType);//获取到未选中的里面的已选中的复选框，并转换成json
	var checkList=getSelFromChecked();//获取到已选中里面的复选框的所有值，并转换成json
	var resultList=getSingleFromSel(selList,checkList);//筛选出已选中的里面没有的值，转换成json
	if(resultList.length>0){
		insertToSel(resultList);
	}
}
//获取可选列选中状态
function getCheckList(id){
	var	selObj=document.getElementById(id);
	if(selObj.checked){
		var html=$("#optinalList").html();
		var temp="";
		temp=temp+"<li id=\""+selObj.value+"_li\" class=\"bg-selected\" field-name="+selObj.value+"><input type=\"checkbox\" style=\"display:none\" name=\"seled\" value="+selObj.value+" />"+$("#"+selObj.value).html()+" </li>";
		html=html+temp;
		$("#optinalList").html(html);
	}else{
		$("#"+selObj.value+"_li").remove();
	}
}
//全选操作
function getCheckListAll(obj,fieldType){
	var checkList=document.getElementsByName(fieldType);
	for(var i=0;i<checkList.length;i++){
		checkList[i].checked=obj.checked;
		if(checkList[i].checked){
			if(i==0){
				$("#optinalList").empty();
			}
			var html=$("#optinalList").html();
			var temp="";
			temp=temp+"<li id=\""+checkList[i].value+"_li\" class=\"bg-selected\" field-name="+checkList[i].value+"><input type=\"checkbox\" style=\"display:none\" name=\"seled\" value="+checkList[i].value+" /> "+$("#"+checkList[i].value).html()+" </li>";
			html=html+temp;
			$("#optinalList").html(html);
		}else{
			$("#"+checkList[i].value+"_li").remove();
		}
	}
	
}

function remove(fieldType){
	//移除所有选中的
	var pastLen=0;
	var checkList=document.getElementsByName(fieldType);
	pastLen=checkList.length;
	var selList="";
	for(var i=0;i<checkList.length;i++){
		if(checkList[i].checked){
			//alert(i);
			var val=checkList[i].value;
			document.getElementById(val+"C").checked=false;
			selList=selList+","+val;
		}
	}
	selList=selList.substring(1,selList.length);
	var selArr=selList.split(",");
	for(var i=0;i<selArr.length;i++){
		$("#"+selArr[i]+"_li").remove();
	}
	if(pastLen==selArr.length){
		document.getElementById("selF").checked=false;
	}
}
//获取未选列中已选中的的字段
function getSelList(fieldType){
	var	selObjs=document.getElementsByName(fieldType);
	var selList="";
	var result;
	for(var i=0;i<selObjs.length;i++){
	if(selObjs[i].checked){
			selList=selList+",{\"name\":\""+$("#"+selObjs[i].value).html()+"\",\"value\":\""+selObjs[i].value+"\"}";
		}
	}
	selList=selList.substring(1,selList.length);
	result=eval('([' + selList + '])');
	return result;
}
//筛选出未选中的字段
function getSingleFromSel(selList,checkList){
	var flag=true;
	var resultList="";
	var result;
	for(var i=0;i<selList.length;i++){
		flag=true;
		for(var j=0;j<checkList.length;j++){
			if(selList[i].value==checkList[j].value){
				flag=false;
			}
		}
		if(flag){
			resultList=resultList+",{\"name\":\""+selList[i].name+"\",\"value\":\""+selList[i].value+"\"}";
		}
	}
	resultList=resultList.substring(1,resultList.length);
	result=eval('([' + resultList + '])');
	return result;
}
//追加到以选择的字段中去
function insertToSel(resultList){
	var html=$("#optinalList").html();
	var temp="";
	for(var i=0;i<resultList.length;i++){
		temp=temp+"<li id=\""+resultList[i].value+"_li\" class=\"bg-selected\" field-name="+resultList[i].value+"><input type=\"checkbox\" name=\"seled\" value="+resultList[i].value+" /> "+resultList[i].name+" </li>";
	}
	html=html+temp;
	$("#optinalList").html(html);
}
//获取以选择列中的所有字段
function getSelFromChecked(){
	var	selObjs=document.getElementsByName("seled");
	var selList="";
	var result;
	for(var i=0;i<selObjs.length;i++){
			selList=selList+",{\"name\":\""+$("#"+selObjs[i].value).html()+"\",\"value\":\""+selObjs[i].value+"\"}"
	}
	selList=selList.substring(1,selList.length);
	result=eval('([' + selList + '])');
	return result;
}

//全选
function doSelAll(obj,fieldType){
	var selList=document.getElementsByName(fieldType);
	for(var i=0;i<selList.length;i++){
		selList[i].checked=obj.checked;
	}
}


function initUpload1(basePath){
	//增加对 302 跳转的处理 (2015.12.23)
	var docUnid=$("#id").val();
	if(typeof(docUnid) == "undefined"){
		docUnid=$("#docUnid").val();
	}
	//302 End
	var fileTypeExts=$("#fileTypeExts").val();
	//var fileSizeLimit=$("#fileSizeLimit").val();
	var fileSizeLimit="100MB";
	var savePath=$("#savePath").val();
	var multi=$("#multi").val();
	var type=$("#type").val();
	var textList=$("#textList").html();//attList用于判断当前是否是上传文本哪里的空间，如果是则改变需要显示的文字
	if(textList==undefined){
		if(type=="contractAtt"){
			type="合同文本上传";
		}else if(type=="buchongxieyiAtt"){
			type="补充协议文本上传";
		}else if(type=="zhongzhixieyiAtt"){
			type="终止协议文本上传";
		}else if(type=="intentAtt"){
			type="意向书文本上传";
		}else if(type=="pic"){
			type="图片上传";
		}else{
			type="上传附件";
		}
	}else{
		type="上传附件";
	}
	var fileType="";
	var uploadLimit=5;
	$("#uploadify").uploadify({  
        'height'        : 25,   
        'width'         : 110,    
        'buttonText'    : type,  
        'swf'           : basePath+'uploadify/uploadify.swf',  
        'uploader'      : basePath+'file/fileUpload',
        'langFile'      : basePath+'uploadify/zh_cn.js',
        'auto'          : true,
        'removeCompleted':false,
        'fileTypeExts'  :fileTypeExts,
        'fileSizeLimit':fileSizeLimit,
        'cancelImg':basePath+'uploadify/uploadify-cancel.png',
        'queueSizeLimit' :uploadLimit,
        'multi':multi,   
        'formData':{
            'savePath': savePath,
            'docUnid':docUnid
        },
        'onUploadStart' : function(file){
            //开始上传..
           // mask();
        },
        'onUploadSuccess':function(file, data, response){
        	var cancel=$("#"+file.id + " .cancel a");
        	if (cancel) {
        	    cancel.on('click',function () {
	        	    //在这此处处理...
	        	    //通过uploadify的settings方式重置上传限制数量
	        	    $('#upload').uploadify('settings','uploadLimit', ++uploadLimit);
	        	    cancerFile(file.id);
	        	    //防止手快多点几次x，把x隐藏掉
	        	    $(this).hide();
        	    });
        	}
        	$('#' + file.id).find('.data').html(' 上传完毕');
        	
        	//alert(data);
        	//302处理
        	try{
        		data=eval('('+data+')');
        	}catch(e){
        		var url = "uc_document/documentTemplate/getFileIdFor302_"+docUnid;
        		jQuery.ajax({
        	        type: "post",
        	        async: false,          
        	        url: url,
        	        contentType: "application/json; charset=utf-8",
        	        dataType: "json",
        	        cache: false,
        	        success: function (info) {
        	        	data = info;
        	        }
        	    });
        	}
            if(data.success=="true"){
            	layer.alert("网络忙，稍后重试",{icon:7});
            }else{
            	$('#' + file.id).append("<input type='hidden' id='"+file.id+"_id' value='"+data.msg+"' />" );
            	var attids=$("#attids").val();
            	if(attids==""){
            		attids=data.msg;
            	}else{
            		attids=attids+","+data.msg;
            	}
            	$("#attids").val(attids);
            	//alert(attids);
            	$("#fileName").val(file.name);
            	//alert($("#attids").val());
            }
            fileType=file.name.substring(file.name.lastIndexOf("."),file.name.length);
            if($("#preView")!=null){
        	    var imgUrl="<img style='width:300px;' src='"+basePath+"upload/headImg/temp/"+$("#sys_userid").val()+fileType+"' />";
        	    $("#preView").html(imgUrl);
            }
            //预览上传图片
            if($("#yulan")!=null && attids!=""){
            	var ids=attids.split(",");
            	var imgSrc="";
            	for(var i=0;i<ids.length;i++){
            		imgSrc+="<img src='upload/pic/"+ids[i]+fileType+"' width='120' height='120' id='"+ids[i]+"' />";
            	}
            	$("#yulan").html(imgSrc);
            }
        }
    });
}
function doUpload(){
	$('#uploadify').uploadify('upload');
}
//删除服务器已上传的文件
function cancerFile(id){
		  var docUnid=$("#"+id+"_id").val();
		  var hostName=$("base").attr("href");
			var url=hostName+"/file/del";
			jQuery.ajax({
		        type:"post",
		        async:false,
		        url:url,
		        dataType:"json",
		        data:{attId:docUnid},
		        success:function(data){
		        	if(data.success){
		        		layer.alert(data.msg,{icon:6},function(i){
		        			layer.close(i);
		        			deleteDocUnid($("#attids").val(),docUnid);
		        			//预览图片中删掉去除的图片
		        			$("#"+id).remove();
		        		});
		        	}else{
		        		layer.alert(data.msg,{icon:7});
		        	}
		        }
			});	  
}


/**
 * layui的上传按钮
 * */
function initUpload(basePath){
	//增加对 302 跳转的处理 (2015.12.23)
	var docUnid=$("#id").val();
	if(typeof(docUnid) == "undefined"){
		docUnid=$("#docUnid").val();
	}
	//302 End
	var fileTypeExts='file';
	if($("#fileTypeExts").val() == 'images'){
		fileTypeExts = 'images';
	}
	var savePath=$("#savePath").val();
	var multi=eval($("#multi").val());
	var type=$("#type").val();
	var textList=$("#textList").html();//attList用于判断当前是否是上传文本哪里的空间，如果是则改变需要显示的文字
	if(textList==undefined){
		if(type=="contractAtt"){
			type="合同文本上传";
		}else if(type=="buchongxieyiAtt"){
			type="补充协议文本上传";
		}else if(type=="zhongzhixieyiAtt"){
			type="终止协议文本上传";
		}else if(type=="intentAtt"){
			type="意向书文本上传";
		}else if(type=="pic"){
			type="图片上传";
		}else{
			type="上传附件";
		}
	}else{
		type="上传附件";
	}
	var fileType="";
	var uploadLimit=5;
	$("#uploadBtn").text(type);
	layui.use(['upload','element'],function(){
		var upload = layui.upload,element = layui.element;
		 var xhrOnProgress=function(fun) {
			xhrOnProgress.onprogress = fun; //绑定监听
			 //使用闭包实现监听绑
			return function() {
				//通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
				var xhr = $.ajaxSettings.xhr();
				 //判断监听函数是否为函数
				  if (typeof xhrOnProgress.onprogress !== 'function')
				       return xhr;
				   //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
				    if (xhrOnProgress.onprogress && xhr.upload) {
				          xhr.upload.onprogress = xhrOnProgress.onprogress;
				    }
				    return xhr;
			 }
		 }
		var up = upload.render({
			elem:'#uploadBtn',
			url:basePath+'file/fileUpload',
			accept:fileTypeExts,
			data:{
				'savePath': savePath,
	            'docUnid':docUnid
			},
			multiple:multi,
			xhr:xhrOnProgress,
			progress:function(index,value){//上传进度回调 value进度值
				element.progress('file'+index, value+'%');//设置页面进度条
			 },
			choose:function(obj){
				var files = this.files = obj.pushFile();
				obj.preview(function(index,file,result){
					$("#uploadify-queue").append('<div id="'+index+'" class="uploadify-queue-item" >'
							+'<div class="cancel">'
							+'	<a href="javascript:cancerFile(\''+index+'\')">X</a>'	
							+'</div>'	
							+'<span class="fileName">'+file.name+'</span><span class="data" style="color:#1e9fff;margin-left:10px;"> 上传中</span>'	
							+'<div class="layui-progress" style="margin-top:10px" lay-showPercent="yes" lay-filter="file'+index+'">'
							 +'<div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>'
							  +'</div><input type="hidden" id="'+index+'_id" value=""></div>');
	        	
				})
			},
			done:function(data,index,upload){
				if(data.success){
					$("#"+index+"_id").val(data.msg);
					$('#' + index).find('.data').html(' 上传完毕');
	            	var attids=$("#attids").val();
	            	if(attids==""){
	            		attids=data.msg;
	            	}else{
	            		attids=attids+","+data.msg;
	            	}
	            	$("#attids").val(attids);
		            var file = this.files[index];
		            fileType=file.name.substring(file.name.lastIndexOf("."),file.name.length);
		            if($("#preView")!=null){
		        	    var imgUrl="<img style='width:300px;' src='"+basePath+"upload/headImg/temp/"+$("#sys_userid").val()+fileType+"' />";
		        	    $("#preView").html(imgUrl);
		            }
		            //预览上传图片
		            if($("#yulan")!=null && attids!=""){
		            	var ids=attids.split(",");
		            	var imgSrc="";
		            	for(var i=0;i<ids.length;i++){
		            		imgSrc+="<img src='upload/pic/"+ids[i]+fileType+"' width='120' height='120' id='"+ids[i]+"' />";
		            	}
		            	$("#yulan").html(imgSrc);
		            }
		            delete this.files[index];//删除已成功上传的文件
				}else{
					layer.alert("网络忙，稍后重试",{icon:7});
				}
			}
		})
	})
	
}
//删除隐藏域中的id
function deleteDocUnid(oldStr,delStr){
	var resultStr="";
	var strArr=oldStr.split(",");
	for(var i=0;i<strArr.length;i++){
		if(delStr!=strArr[i]){
			if(resultStr==""){
				resultStr=strArr[i];
			}else{
				resultStr=resultStr+","+strArr[i];
			}
		}
	}
	$("#attids").val(resultStr);
	
}

/************************************表单验证***********************************/
//手机号
function checkMobile(str) {
   var re = /^1\d{10}$/
   if (re.test(str)) {
       return true;
   } else {
	   return false;
   }
}
//数字(带小数点)
function checkNumber(str){
	var re = /^[\+\-]?\d*?\.?\d*?$/ 
	if (re.test(str)) {
		return true;
	}else {
		return false;
    }
}
//包含0的正整数
function checkNum(str){
	var re=/^\d+$/
	if (re.test(str)) {
		return true;
	}else {
		return false;
    }
}
/************************************合同表单相关的********************************/
//获取租金单价的json
function getRentPriceJson(){
	var i=0;
	var resultJson="[";
	var result="";
	var sdate="";
	var edate="";
	var zj="";
	var yzj="";
	var rentId="";
	var length=$("#djList").find("tr").length-1;
	for(var i=0;i<length;i++){
			sdate=$("#sdate"+i).val();
			edate=$("#edate"+i).val();
			zj=$("#zujin"+i).val();
			yzj=$("#yzj"+i).val();
			rentId=$("#rentId"+i).val();
			if(result==""){
				result="{\"sdate\":\""+sdate+"\",\"edate\":\""+edate+"\",\"zj\":\""+$.trim(zj)+"\",\"yzj\":\""+$.trim(yzj)+"\",\"id\":\""+rentId+"\"}";
			}else{
				result=result+",{\"sdate\":\""+sdate+"\",\"edate\":\""+edate+"\",\"zj\":\""+$.trim(zj)+"\",\"yzj\":\""+$.trim(yzj)+"\",\"id\":\""+rentId+"\"}";
			}
	}
	resultJson=resultJson+result+"]";
	return resultJson;
}
//获取免租期json
function getFreePriceJson(){
	var resultJson="[";
	var result="";
	var sdate="";
	var edate="";
	var total="";
	var id="";
	var length=$("#dynMzq").find("tr").length-1;
	for(var i=0;i<length;i++){
		sdate=$("#mzq_s"+i).val();
		edate=$("#mzq_e"+i).val();
		total=$("#mzqAll"+i).val();
		id=$("#id"+i).val();
		if(result==""){
			result="{\"mzq_s\":\""+sdate+"\",\"mzq_e\":\""+edate+"\",\"total\":"+$.trim(total)+",\"id\":\""+id+"\"}";
		}else{
			result=result+",{\"mzq_s\":\""+sdate+"\",\"mzq_e\":\""+edate+"\",\"total\":"+$.trim(total)+",\"id\":\""+id+"\"}";
		}
	}
	resultJson=resultJson+result+"]";
	return resultJson;
}
//获取应收json
function getYSJson(){ 
	var resultJson="[";
	var result="";
	var date="";
	var price="";
	var receivableId="";
	var length=$("#ysList").find("tr").length-1;
	for(var i=0;i<length;i++){
		if($("#jine"+i).val()){			
			date=$("#dateYear"+i).val()+"-"+$("#dateMonth"+i).val();
			price=$("#jine"+i).val();
			receivableId=$("#receivableId"+i).val();
			if(result==""){
				result="{\"date\":\""+date+"\",\"price\":\""+$.trim(price)+"\",\"id\":\""+receivableId+"\"}";
			}else{
				result=result+",{\"date\":\""+date+"\",\"price\":\""+$.trim(price)+"\",\"id\":\""+receivableId+"\"}";
			}
		}
	}
	resultJson=resultJson+result+"]";
	return resultJson;
}

//新增应收行
function addYSLine(){
	var length=$("#ysList").find("tr").length-1; //行数
	var lastIndex = length-1; //最后一行数据索引
	var payment = $("#fk_payment").find("option:selected").text();;
	var year = "2016";
	var month = "01";
	if($("#dateMonth"+lastIndex).val()!=""){
		month = $("#dateMonth"+lastIndex).val();
	}
	if(payment=="月付"){
		month = parseInt(month)+1;
	}else if(payment=="季付"){
		month = parseInt(month)+3;
	}else if(payment=="半年付"){
		month = parseInt(month)+6;
	}else if(payment=="年付"){
		month = parseInt(month)+12;
	}
	if($("#dateYear"+lastIndex).val()!=""){
		year = $("#dateYear"+lastIndex).val();
	}
	
	//计算
	if(month>12){
		month = month%12;
		year = parseInt(year)+1;
	}
	
	if(parseInt(month)<10){
		month="0"+parseInt(month);
	}
	//第一次
	if(typeof(year)=="undefined"){
		var startDate = $("#sdate").val();
		year = startDate.substring(0,4);
		month = startDate.substring(5,7);
	}
	var trHTML = "<tr id='ys"+length+"'><td>第"+(length+1)+"次<input type='hidden' name='receivableId"+length+"' id='receivableId"+length+"' value='' /> </td><td>年:<input size='10' type='text' name='dateYear"+length+"' id='dateYear"+length+"' value='"+year+"'/>&nbsp;<input type='button' value='+' onclick=calcAdd('dateYear"+length+"') />&nbsp;<input type='button' value='-' onclick=calcJian('dateYear"+length+"') />&nbsp;月:<input size='10' type='text' name='dateMonth"+length+"'  id='dateMonth"+length+"' value='"+month+"' />&nbsp;<input type='button' value='+' onclick=calcAdd('dateMonth"+length+"') />&nbsp;<input type='button' value='-' onclick=calcJian('dateMonth"+length+"') /></td> <td><input size='10' type='text' id='jine"+length+"' name='jine"+length+"' />元<input type='button' size='10' value='同上' onClick=autoVal("+length+") /> &nbsp; <input type='button' size='10' value='删除' onClick=delYSLine('"+length+"')></td></tr>";
	$("#ysList").find("tbody").append(trHTML);
}

//删除应收行
function delYSLine(index){
	$("#ys"+index).remove();
}

//删除单价行
function delDJLine(index){
	$("#dj"+index).remove();
}

//计算每行的免租期天数
function calTotal(sdate_id,edate_id,total_id){
	var sdate=$("#"+sdate_id).val();
	var edate=$("#"+edate_id).val();
	if(sdate!="" && edate!=""){
		var diffDay=daysBetween(sdate,edate)+1;
		$("#"+total_id).val(diffDay);
	}
}
function checkExsit(){
	var fk_operate=$("#fk_dept").val();
	var numberHeadName=$("#headName").val();
	var contractNumber=$.trim($("#contractNum").val());
	var contractId=$("#contractId").val();
	var url="uc_contract/contractInfo/checkExsit";
	var flag=false;
	jQuery.ajax({
        type:"post",
        async:false,
        url:url,
        dataType:"json",
        data:{fk_operate:fk_operate,numberHeadName:numberHeadName,contractNumber:contractNumber,contractId:contractId},
        success:function(data){
        	if(data.success){   		
        			flag=true;
        	}else{
        		flag=false;
        	}
        }
	});
	return flag;
}
function changeText(){
	var isProxy=$("#hasProxy").val();
	if(isProxy=="0"){
		$("#text").hide();
	}else{
		$("#text").show();
	}
	
}